package com.lyf.scm.plan.domain.service.impl;

import cn.hutool.core.date.DateUtil;
import com.lyf.scm.common.constants.CommonConstants;
import com.lyf.scm.common.enums.BigDataChannelEnum;
import com.lyf.scm.common.enums.OpContentEnum;
import com.lyf.scm.common.enums.OperationDataEnum;
import com.lyf.scm.plan.api.dto.StoreInfoDTO;
import com.lyf.scm.plan.domain.convertor.BigDataBaseConvertor;
import com.lyf.scm.plan.domain.remote.bigdata.dto.BigDataGeneralInfoDTO;
import com.lyf.scm.plan.domain.remote.bigdata.dto.BigDataGeneralQueryBaseDTO;
import com.lyf.scm.plan.domain.remote.bigdata.facade.CprfCoreFacade;
import com.lyf.scm.plan.domain.remote.item.dto.CategorySimpleDTO;
import com.lyf.scm.plan.domain.remote.item.dto.SkuInfoDTO;
import com.lyf.scm.plan.domain.remote.item.facade.ItemCoreFacade;
import com.lyf.scm.plan.domain.repository.*;
import com.lyf.scm.plan.domain.service.BigDataAlternativeSolutionService;
import com.lyf.scm.plan.domain.util.BigDataCacheUtil;
import com.lyf.scm.plan.domain.util.OperationLogRecordUtil;
import com.lyf.scm.plan.insfrastructure.db.dataobject.OperationLogRecordDO;
import com.lyf.scm.plan.insfrastructure.db.dataobject.bigdata.*;
import com.rome.arch.util.IdWorker;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.FutureTask;
import java.util.stream.Collectors;

import static com.lyf.scm.plan.domain.util.BigDataCacheUtil.*;

/**
 * 大数据备用解决方案(做更新操作)
 *
 * @author wangchlei
 * @date 2020/10/05
 */
@Slf4j
@Service
public class BigDataAlternativeSolutionServiceImpl implements BigDataAlternativeSolutionService {
    @Resource
    private RedisCacheServiceImpl redisCacheServiceImpl;
    @Resource
    private OperationLogRecordRepository operationLogRecordRepository;
    @Resource
    private DirectlyStoreRepository directlyStoreRepository;
    @Resource
    private DirectlyExecuteRepository directlyExecuteRepository;
    @Resource
    private BigDataBaseConvertor bigDataBaseConvertor;
    @Resource
    private SalesPlanDirectlyAccuracyRepository salesPlanDirectlyAccuracyRepository;
    @Resource
    private SalePlanDirectlyDifferinRepository salePlanDirectlyDifferinRepository;
    @Resource
    private SalesPlanDirectlyRepository salesPlanDirectlyRepository;
    @Resource
    private DirectlyExecuteServiceImpl directlyExecuteServiceImpl;
    @Resource
    private DirectlyStoreServiceImpl directlyStoreServiceImpl;
    @Resource
    private DemandPlanServiceImpl demandPlanServiceImpl;
    @Resource
    private SalesPlanDirectlyAccuracyServiceImpl salesPlanDirectlyAccuracyServiceImpl;
    @Resource
    private SalePlanDirectlyDifferinServiceImpl salePlanDirectlyDifferinServiceImpl;
    @Resource
    private SalesPlanDirectlyServiceImpl salesPlanDirectlyServiceImpl;
    @Resource
    private ExecutorService sonExecutorService;
    /**
     * 远程调用
     */
    @Resource
    private CprfCoreFacade cprfCoreFacade;
    /**
     * 标识
     */
    private String opSign;
    /**
     * 是否触发周任务
     */
    private boolean validWeekJob;
    @Resource
    private ItemCoreFacade itemCoreFacade;

    @Override
    public void handleApiDispatcher() {
        long startTime = System.currentTimeMillis();
        //test 重置所有测试耗时key-value
//        redisServiceImpl.remove("totalTime", "apiTime", "handleResultTime", "mysqlTime","demandTime","storeTime","executeTime","accuracyTime","differTime","directTime");
        Map<String, StoreInfoDTO> storesInfo = redisCacheServiceImpl.getDirectStores();
        log.info("\n【大数据Job】：已获取所有门店,门店数量 {}", storesInfo.size());
        //获取当前时间
        this.initCacheData();
        //动态创建线程池(拒绝策略:由调用者线程执行任务)
        log.info("\n【大数据Job】：开始处理所有门店");
        storesInfo.keySet().forEach(item -> {
//            fatherExecutorService.execute(() ->
            this.handleStore(storesInfo.get(item));
//            });
        });
        long endTime = System.currentTimeMillis();
        this.writeOperateLog(endTime - startTime);
    }

    private void handleStore(StoreInfoDTO storeInfo) {
        //test 总时长（起）
//        long totalTimeStart = System.currentTimeMillis();
//        long totalTimeEnd;
        //直营预测——执行（天）(新增)
        List<DirectlyExecuteInDO> directlyExecuteInDOs = new ArrayList<>();
        //直营预测——执行（天）(更新)
        List<DirectlyExecuteUpDO> directlyExecuteUpDOs = new ArrayList<>();
        List<Long> directlyExecuteRmDOs = new ArrayList<>();
        //直营预测计划——门店（天）
        List<DirectlyStoreInDO> directlyStoreInDOs = new ArrayList<>();
        //直营预测计划——门店（更新）
        List<DirectlyStoreUpDO> directlyStoreUpDOs = new ArrayList<>();
        List<Long> directlyStoreRmDOs = new ArrayList<>();
        //直营准去率（周）（新增）
        List<DirectlyAccuracyInDO> directlyAccuracyInDOs = null;
        //直营准去率（周）（更新）
        List<DirectlyAccuracyUpDO> directlyAccuracyUpDOs = null;
        List<Long> directlyAccuracyRmDOs = null;
        //直营差异（周）（新增）
        List<DirectlyDifferinInDO> directlyDifferinInDOs = null;
        //直营差异（周）（更新）
        List<DirectlyDifferinUpDO> directlyDifferinUpDOs = null;
        List<Long> directlyDifferinRmDOs = null;
        //直营预测（周）（新增）
        List<DirectlyInDO> directlyInDOs = null;
        //直营预测（周）（更新）
        List<DirectlyUpDO> directlyUpDOs = null;
        List<Long> directlyRmDOs = null;
        if (validWeekJob) {
            //(新增) 准确率
            directlyAccuracyInDOs = new ArrayList<>();
            //(更新) 准确率
            directlyAccuracyUpDOs = new ArrayList<>();
            directlyAccuracyRmDOs = new ArrayList<>();
            //(新增) 差异
            directlyDifferinInDOs = new ArrayList<>();
            //（更新）差异
            directlyDifferinUpDOs = new ArrayList<>();
            directlyDifferinRmDOs = new ArrayList<>();
            //(新增) 直营预测
            directlyInDOs = new ArrayList<>();
            //（更新）直营预测
            directlyUpDOs = new ArrayList<>();
            directlyRmDOs = new ArrayList<>();
        }
        //大数据信息
        List<BigDataGeneralInfoDTO> bigDataGeneralInfoDTOs = new ArrayList<>();
        //补获公共异常
        //test api时长
//        long apiTimeStart = 0L;
//        long apiTimeEnd;
        try {
            //获取查询条件
            BigDataGeneralQueryBaseDTO bigDataGeneralQueryBaseDTO = this.getGeneralQueryBaseDTO(storeInfo.getCode(), BigDataCacheUtil.nowDate);
            //根据时间段，门店等信息  递归分页获取所有大数据信息
            //test api时长（起）
//            apiTimeStart = System.currentTimeMillis();
            this.getBigDataGeneralInfo(bigDataGeneralQueryBaseDTO, bigDataGeneralInfoDTOs);
            //test api时长（终）
//            apiTimeEnd = System.currentTimeMillis();
            //合理默认两个表的状态是统一的，且其数据量数据结构是一致的（数据数量，sku,门店等是统一的）
            if (!CollectionUtils.isEmpty(bigDataGeneralInfoDTOs)) {
//                redisServiceImpl.lPush("apiTime", "成功，门店code：" + storeInfo.getCode() + " ；大数据数据总量：" + bigDataGeneralInfoDTOs.size() + " 处理时长：" + (apiTimeEnd - apiTimeStart) + "ms");
                //test 处理结果时长（起）
//                long handleResultTimeStart = System.currentTimeMillis();
                if (validWeekJob) {
                    this.getDayAndWeekResult(storeInfo, bigDataGeneralInfoDTOs, directlyExecuteInDOs, directlyExecuteUpDOs, directlyStoreInDOs, directlyStoreUpDOs, directlyAccuracyInDOs, directlyAccuracyUpDOs, directlyDifferinInDOs, directlyDifferinUpDOs, directlyInDOs, directlyUpDOs, directlyExecuteRmDOs, directlyStoreRmDOs, directlyAccuracyRmDOs, directlyDifferinRmDOs, directlyRmDOs);
                } else {
                    this.getDayResult(storeInfo, bigDataGeneralInfoDTOs, directlyExecuteInDOs, directlyExecuteUpDOs, directlyStoreInDOs, directlyStoreUpDOs, directlyExecuteRmDOs, directlyStoreRmDOs);
                }
                //test 处理结果时长（终）
//                long handleResultTimeEnd = System.currentTimeMillis();
//                redisServiceImpl.lPush("handleResultTime", "成功，门店code：" + storeInfo.getCode() + " ；大数据数据总量：" + bigDataGeneralInfoDTOs.size() + " 处理时长：" + (handleResultTimeEnd - handleResultTimeStart) + "ms");
            } else {
                //test 总时长（终止）
//                totalTimeEnd = System.currentTimeMillis();
//                redisServiceImpl.lPush("totalTime", "成功，门店code：" + storeInfo.getCode() + " ；大数据数据总量：0" + "处理时长：" + (totalTimeEnd - totalTimeStart) + "ms");
                log.warn("\n【大数据Job】：门店数据无数据：code {}  name {}", storeInfo.getCode(), storeInfo.getName());
                return;
            }
        } catch (feign.RetryableException retryableException) {
            //test api时长（终）
//            apiTimeEnd = System.currentTimeMillis();
//            redisServiceImpl.lPush("apiTime", "失败，门店code：" + storeInfo.getCode() + " ；大数据数据总量：" + bigDataGeneralInfoDTOs.size() + " 处理时长：" + (apiTimeEnd - apiTimeStart) + "ms");
            retryableException.printStackTrace();
            log.error("\n【大数据Job】：门店数据处理失败：code {}  name {}", storeInfo.getCode(), storeInfo.getName() + " 失败原因：" + retryableException.getMessage());
            //test 所有异常信息为具体值  而不是不确定值
            this.writeErrorLog(storeInfo.getCode(), retryableException.getMessage());
            return;
        } catch (Exception e) {
            //test api时长（终）
//            apiTimeEnd = System.currentTimeMillis();
//            redisServiceImpl.lPush("apiTime", "失败，门店code：" + storeInfo.getCode() + " ；大数据数据总量：" + bigDataGeneralInfoDTOs.size() + " 处理时长：" + (apiTimeEnd - apiTimeStart) + "ms");
            e.printStackTrace();
            log.error("\n【大数据Job】：门店数据处理失败：code {}  name {}", storeInfo.getCode(), storeInfo.getName() + " 失败原因：数据处理异常");
            //test 所有异常信息为具体值  而不是不确定值
            this.writeErrorLog(storeInfo.getCode(), "数据处理异常");
            return;
        }
//        long mysqlTimeStart = System.currentTimeMillis();
        FutureTask<String> directlyExecuteFutureTask = new FutureTask<>(() -> {
            try {
                directlyExecuteServiceImpl.handleUpBigData(directlyExecuteInDOs, directlyExecuteUpDOs, directlyExecuteRmDOs);
            } catch (Exception e) {
                e.printStackTrace();
                log.error("\n【大数据（日）销售预测Job】：门店数据处理失败：code {}  name {}", storeInfo.getCode(), storeInfo.getName() + " 失败原因：数据插入异常");
                operationLogRecordRepository.addBigDataErrorLog(OperationLogRecordUtil.getBigDataErrorLog(storeInfo.getCode(), OperationDataEnum.DIRECTLY_EXECUTE.getTableType(), "数据插入异常", directlyExecuteInDOs.size(), 0 + "ms", OpContentEnum.BIG_DATA_ERROR_DIRECT_LOG.getIndex().toString(),OpContentEnum.BIG_DATA_ERROR_DIRECT_LOG.getDesc()));
                return "failed";
            }
            return "success";
        });
        FutureTask<String> directlyStoreFutureTask = new FutureTask<>(() -> {
            try {
                directlyStoreServiceImpl.handleUpBigData(directlyStoreInDOs, directlyStoreUpDOs, directlyStoreRmDOs);
            } catch (Exception e) {
                e.printStackTrace();
                log.error("\n【大数据（日）销售预测Job】：门店数据处理失败：code {}  name {}", storeInfo.getCode(), storeInfo.getName() + " 失败原因：数据插入异常");
                operationLogRecordRepository.addBigDataErrorLog(OperationLogRecordUtil.getBigDataErrorLog(storeInfo.getCode(), OperationDataEnum.DIRECTLY_SHOP.getTableType(), "数据插入异常", directlyStoreInDOs.size(), 0 + "ms", OpContentEnum.BIG_DATA_ERROR_DIRECT_LOG.getIndex().toString(),OpContentEnum.BIG_DATA_ERROR_DIRECT_LOG.getDesc()));
                return "failed";
            }
            return "success";
        });
        FutureTask<String> demandFutureTask = new FutureTask<>(() -> {
            try {
                demandPlanServiceImpl.handleBigData(bigDataGeneralInfoDTOs, opSign, storeInfo.getCode(), startDate1);
            } catch (Exception e) {
                e.printStackTrace();
                log.error("\n【大数据（日）销售预测Job】：门店数据处理失败：code {}  name {}", storeInfo.getCode(), storeInfo.getName() + " 失败原因：数据更新异常");
                operationLogRecordRepository.addBigDataErrorLog(OperationLogRecordUtil.getBigDataErrorLog(storeInfo.getCode(), OperationDataEnum.PLAN_DEMAND.getTableType(), "数据更新异常", bigDataGeneralInfoDTOs.size(), 0 + "ms", OpContentEnum.BIG_DATA_ERROR_DIRECT_LOG.getIndex().toString(),OpContentEnum.BIG_DATA_ERROR_DIRECT_LOG.getDesc()));
                return "failed";
            }
            return "success";
        });
        FutureTask<String> directlyAccuracyFutureTask = null;
        FutureTask<String> directlyDifferinFutureTask = null;
        FutureTask<String> directlyFutureTask = null;
        if (validWeekJob) {
            List<DirectlyAccuracyInDO> finalDirectlyAccuracyInDOs = directlyAccuracyInDOs;
            List<DirectlyAccuracyUpDO> finalDirectlyAccuracyUpDOs = directlyAccuracyUpDOs;
            List<Long> finalDirectlyAccuracyRmDOs = directlyAccuracyRmDOs;
            directlyAccuracyFutureTask = new FutureTask<>(() -> {
                try {
                    salesPlanDirectlyAccuracyServiceImpl.handleUpBigData(finalDirectlyAccuracyInDOs, finalDirectlyAccuracyUpDOs, finalDirectlyAccuracyRmDOs);
                } catch (Exception e) {
                    e.printStackTrace();
                    log.error("\n【大数据（周）销售预测Job】：门店数据处理失败：code {}  name {}", storeInfo.getCode(), storeInfo.getName() + " 失败原因：数据插入异常");
                    operationLogRecordRepository.addBigDataErrorLog(OperationLogRecordUtil.getBigDataErrorLog(storeInfo.getCode(), OperationDataEnum.DIRECTLY_ACCURACY.getTableType(), "数据插入异常", finalDirectlyAccuracyInDOs.size(), 0 + "ms", OpContentEnum.BIG_DATA_ERROR_DIRECT_LOG.getIndex().toString(),OpContentEnum.BIG_DATA_ERROR_DIRECT_LOG.getDesc()));
                    return "failed";
                }
                return "success";
            });
            List<DirectlyDifferinInDO> finalDirectlyDifferinInDOs = directlyDifferinInDOs;
            List<Long> finalDirectlyDifferinRmDOs = directlyDifferinRmDOs;
            List<DirectlyDifferinUpDO> finalDirectlyDifferinUpDOs = directlyDifferinUpDOs;
            directlyDifferinFutureTask = new FutureTask<>(() -> {
                try {
                    salePlanDirectlyDifferinServiceImpl.handleUpBigData(finalDirectlyDifferinInDOs, finalDirectlyDifferinUpDOs, finalDirectlyDifferinRmDOs);
                } catch (Exception e) {
                    e.printStackTrace();
                    log.error("\n【大数据（周）销售预测Job】：门店数据处理失败：code {}  name {}", storeInfo.getCode(), storeInfo.getName() + " 失败原因：数据插入异常");
                    operationLogRecordRepository.addBigDataErrorLog(OperationLogRecordUtil.getBigDataErrorLog(storeInfo.getCode(), OperationDataEnum.DIRECTLY_DIFFERIN.getTableType(), "数据插入异常", finalDirectlyDifferinInDOs.size(), 0 + "ms", OpContentEnum.BIG_DATA_ERROR_DIRECT_LOG.getIndex().toString(),OpContentEnum.BIG_DATA_ERROR_DIRECT_LOG.getDesc()));
                    return "failed";
                }
                return "success";
            });
            List<DirectlyInDO> finalDirectlyInDOs = directlyInDOs;
            List<DirectlyUpDO> finalDirectlyUpDOs = directlyUpDOs;
            List<Long> finalDirectlyRmDOs = directlyRmDOs;
            directlyFutureTask = new FutureTask<>(() -> {
                try {
                    // salesPlanDirectlyServiceImpl.handleUpBigData(finalDirectlyInDOs, finalDirectlyUpDOs, finalDirectlyRmDOs);
                } catch (Exception e) {
                    e.printStackTrace();
                    log.error("\n【大数据（周）销售预测Job】：门店数据处理失败：code {}  name {}", storeInfo.getCode(), storeInfo.getName() + " 失败原因：数据插入异常");
                    operationLogRecordRepository.addBigDataErrorLog(OperationLogRecordUtil.getBigDataErrorLog(storeInfo.getCode(), OperationDataEnum.PLAN_DIRECTLY.getTableType(), "数据插入异常", finalDirectlyInDOs.size(), 0 + "ms", OpContentEnum.BIG_DATA_ERROR_DIRECT_LOG.getIndex().toString(),OpContentEnum.BIG_DATA_ERROR_DIRECT_LOG.getDesc()));
                    return "failed";
                }
                return "success";
            });
            sonExecutorService.execute(directlyAccuracyFutureTask);
            sonExecutorService.execute(directlyDifferinFutureTask);
            sonExecutorService.execute(directlyFutureTask);
        }
        sonExecutorService.execute(directlyExecuteFutureTask);
        sonExecutorService.execute(directlyStoreFutureTask);
        sonExecutorService.execute(demandFutureTask);
        String executeFutureResult = null;
        String storeFutureResult = null;
        String demandResult = null;
        String accuracyFutureResult = "success";
        String directlyDifferinFutureResult = "success";
        String directlyFutureResult = "success";
        try {
            executeFutureResult = directlyExecuteFutureTask.get();
            storeFutureResult = directlyStoreFutureTask.get();
            demandResult = demandFutureTask.get();
            if (validWeekJob) {
                accuracyFutureResult = directlyAccuracyFutureTask.get();
                directlyDifferinFutureResult = directlyDifferinFutureTask.get();
                directlyFutureResult = directlyFutureTask.get();
            }
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }
//        long mysqlTimeEnd = System.currentTimeMillis();
//        redisServiceImpl.lPush("mysqlTime", "成功，门店code：" + storeInfo.getCode() + " ；大数据数据总量：" + bigDataGeneralInfoDTOs.size() + " 处理时长：" + (mysqlTimeEnd - mysqlTimeStart) + "ms");
        if ("success".equals(executeFutureResult) && "success".equals(storeFutureResult) && "success".equals(demandResult) && "success".equals(accuracyFutureResult) && "success".equals(directlyDifferinFutureResult) && "success".equals(directlyFutureResult)) {
            //test 总时长（终止）
//            totalTimeEnd = System.currentTimeMillis();
//            redisServiceImpl.lPush("totalTime", "成功，门店code：" + storeInfo.getCode() + " ；大数据数据总量：" + bigDataGeneralInfoDTOs.size() + " 处理时长：" + (totalTimeEnd - totalTimeStart) + "ms");
            log.info("\n【大数据Job】：门店数据处理成功：code {}  name {}", storeInfo.getCode(), storeInfo.getName());
        }
    }

    private void writeErrorLog(String storeCode, String msg) {
        List<OperationLogRecordDO> operationLogRecordDOs = new ArrayList<>(6);
        operationLogRecordDOs.add(OperationLogRecordUtil.getBigDataErrorLog(storeCode, OperationDataEnum.DIRECTLY_EXECUTE.getTableType(), msg, 0L, 0 + "ms", OpContentEnum.BIG_DATA_ERROR_DIRECT_LOG.getIndex().toString(),OpContentEnum.BIG_DATA_ERROR_DIRECT_LOG.getDesc()));
        operationLogRecordDOs.add(OperationLogRecordUtil.getBigDataErrorLog(storeCode, OperationDataEnum.DIRECTLY_SHOP.getTableType(), msg, 0L, 0 + "ms", OpContentEnum.BIG_DATA_ERROR_DIRECT_LOG.getIndex().toString(),OpContentEnum.BIG_DATA_ERROR_DIRECT_LOG.getDesc()));
        operationLogRecordDOs.add(OperationLogRecordUtil.getBigDataErrorLog(storeCode, OperationDataEnum.PLAN_DEMAND.getTableType(), msg, 0L, 0 + "ms", OpContentEnum.BIG_DATA_ERROR_DIRECT_LOG.getIndex().toString(),OpContentEnum.BIG_DATA_ERROR_DIRECT_LOG.getDesc()));
        if (validWeekJob) {
            operationLogRecordDOs.add(OperationLogRecordUtil.getBigDataErrorLog(storeCode, OperationDataEnum.DIRECTLY_ACCURACY.getTableType(), msg, 0L, 0 + "ms", OpContentEnum.BIG_DATA_ERROR_DIRECT_LOG.getIndex().toString(),OpContentEnum.BIG_DATA_ERROR_DIRECT_LOG.getDesc()));
            operationLogRecordDOs.add(OperationLogRecordUtil.getBigDataErrorLog(storeCode, OperationDataEnum.DIRECTLY_DIFFERIN.getTableType(), msg, 0L, 0 + "ms", OpContentEnum.BIG_DATA_ERROR_DIRECT_LOG.getIndex().toString(),OpContentEnum.BIG_DATA_ERROR_DIRECT_LOG.getDesc()));
            operationLogRecordDOs.add(OperationLogRecordUtil.getBigDataErrorLog(storeCode, OperationDataEnum.PLAN_DIRECTLY.getTableType(), msg, 0L, 0 + "ms", OpContentEnum.BIG_DATA_ERROR_DIRECT_LOG.getIndex().toString(),OpContentEnum.BIG_DATA_ERROR_DIRECT_LOG.getDesc()));
        }
        operationLogRecordRepository.batchAddBigDataErrorLog(operationLogRecordDOs);
    }

    private void getDayResult(StoreInfoDTO storeInfo, List<BigDataGeneralInfoDTO> bigDataGeneralInfoDTOs, List<DirectlyExecuteInDO> directlyExecuteInDOs, List<DirectlyExecuteUpDO> directlyExecuteUpDOS, List<DirectlyStoreInDO> directlyStoreInDOs, List<DirectlyStoreUpDO> directlyStoreUpDOS, List<Long> directlyExecuteRmDOS, List<Long> directlyStoreRmDOS) {
        //直营预测——门店 根据门店和日期获取所有需要更新的数据（默认为13天数据，今日起）
        List<DirectlyStoreUpDO> directlyStoreDOs = directlyStoreRepository.listUpByStoreAndDate(storeInfo.getCode(), BigDataCacheUtil.dayStartDate, BigDataCacheUtil.dayUpEndDate);
        //直营预测执行
        List<DirectlyExecuteUpDO> directlyExecuteDOS = directlyExecuteRepository.listUpByStoreAndDate(storeInfo.getCode(), BigDataCacheUtil.dayStartDate, BigDataCacheUtil.dayUpEndDate);
        if (CollectionUtils.isEmpty(directlyStoreDOs)) {
            directlyStoreDOs = new ArrayList<>(1);
        }
        if (CollectionUtils.isEmpty(directlyExecuteDOS)) {
            directlyExecuteDOS = new ArrayList<>(1);
        }
        //查询sku信息
        List<SkuInfoDTO> skuInfoDTOS = itemCoreFacade.skuListBySkuCodes(bigDataGeneralInfoDTOs.stream().map(BigDataGeneralInfoDTO::getSkuKey).distinct().collect(Collectors.toList()));
        Map<String, SkuInfoDTO> skuCodeName = this.getSkuInfo(skuInfoDTOS);
        Map<Integer, List<CategorySimpleDTO>> categoryInfo = this.getCategoryInfo(skuInfoDTOS);
        int count;
        List<DirectlyStoreUpDO> tmp;
        //新增sku
        String skuKey;
        BaseInDO baseInDO;
        for (BigDataGeneralInfoDTO bigDataGeneralInfoDTO : bigDataGeneralInfoDTOs) {
            skuKey = bigDataGeneralInfoDTO.getSkuKey();
            //直营预测————门店
            count = 0;
            tmp = new ArrayList<>();
            for (DirectlyStoreUpDO storeDO : directlyStoreDOs) {
                //如果是同一条sku,默认取十三天为更新数据，第十四条为新增数据 存入集合中
                if (skuKey.equals(storeDO.getSkuCode())) {
                    //更新其同用属性（区域，品类）
                    this.setGeneralInfo(storeDO, skuKey, storeInfo, skuCodeName, categoryInfo);
                    //更新其预测值
                    this.setStorePredictValue(storeDO, bigDataGeneralInfoDTO);
                    tmp.add(storeDO);
                    count++;
                }
            }
            //如果已存在数据含有该条sku，直营预测执行  获得需要更新的十三天数据，门店和执行新增第十四日数据
            baseInDO = this.createGeneralDayInDO(skuKey, storeInfo, skuCodeName, categoryInfo);
            if (count == 13) {
                directlyStoreUpDOS.addAll(tmp);
                for (DirectlyExecuteUpDO executeDO : directlyExecuteDOS) {
                    //如果是同一条sku,默认取十三天为更新数据，第十四条为新增数据 存入集合中
                    if (skuKey.equals(executeDO.getSkuCode())) {
                        //更新其同用属性（区域，品类）
                        this.setGeneralInfo(executeDO, skuKey, storeInfo, skuCodeName, categoryInfo);
                        //更新其预测值
                        this.setExecutePredictValue(executeDO, bigDataGeneralInfoDTO);
                        directlyExecuteUpDOS.add(executeDO);
                    }
                }
                //加入第十四天数据，门店和执行
                directlyStoreInDOs.add(this.getNewDirectlyStore(baseInDO, bigDataGeneralInfoDTO.getSalesDayf14()));
                directlyExecuteInDOs.add(this.getNewDirectlyExecute(baseInDO, bigDataGeneralInfoDTO.getSalesDayf14()));
            } else {
                //处理消失过的sku
                if (count != 0) {
                    for (DirectlyExecuteUpDO executeDO : directlyExecuteDOS) {
                        //如果是同一条sku,默认取十三天为更新数据，第十四条为新增数据 存入集合中
                        if (skuKey.equals(executeDO.getSkuCode())) {
                            directlyExecuteRmDOS.add(executeDO.getId());
                        }
                    }
                    directlyStoreRmDOS.addAll(tmp.stream().map(DirectlyStoreUpDO::getId).collect(Collectors.toList()));
                }
                //如果不存在该条sku或不满足14条,两张表都做新增操作，删除旧数据
                this.getDayDO(baseInDO, directlyExecuteInDOs, directlyStoreInDOs, bigDataGeneralInfoDTO.getSalesDayf1(), day1);
                this.getDayDO(baseInDO, directlyExecuteInDOs, directlyStoreInDOs, bigDataGeneralInfoDTO.getSalesDayf2(), day2);
                this.getDayDO(baseInDO, directlyExecuteInDOs, directlyStoreInDOs, bigDataGeneralInfoDTO.getSalesDayf3(), day3);
                this.getDayDO(baseInDO, directlyExecuteInDOs, directlyStoreInDOs, bigDataGeneralInfoDTO.getSalesDayf4(), day4);
                this.getDayDO(baseInDO, directlyExecuteInDOs, directlyStoreInDOs, bigDataGeneralInfoDTO.getSalesDayf5(), day5);
                this.getDayDO(baseInDO, directlyExecuteInDOs, directlyStoreInDOs, bigDataGeneralInfoDTO.getSalesDayf6(), day6);
                this.getDayDO(baseInDO, directlyExecuteInDOs, directlyStoreInDOs, bigDataGeneralInfoDTO.getSalesDayf7(), day7);
                this.getDayDO(baseInDO, directlyExecuteInDOs, directlyStoreInDOs, bigDataGeneralInfoDTO.getSalesDayf8(), day8);
                this.getDayDO(baseInDO, directlyExecuteInDOs, directlyStoreInDOs, bigDataGeneralInfoDTO.getSalesDayf9(), day9);
                this.getDayDO(baseInDO, directlyExecuteInDOs, directlyStoreInDOs, bigDataGeneralInfoDTO.getSalesDayf10(), day10);
                this.getDayDO(baseInDO, directlyExecuteInDOs, directlyStoreInDOs, bigDataGeneralInfoDTO.getSalesDayf11(), day11);
                this.getDayDO(baseInDO, directlyExecuteInDOs, directlyStoreInDOs, bigDataGeneralInfoDTO.getSalesDayf12(), day12);
                this.getDayDO(baseInDO, directlyExecuteInDOs, directlyStoreInDOs, bigDataGeneralInfoDTO.getSalesDayf13(), day13);
                this.getDayDO(baseInDO, directlyExecuteInDOs, directlyStoreInDOs, bigDataGeneralInfoDTO.getSalesDayf14(), day14);
            }
        }
        //获取需要删除的sku（根据id删除）
        this.getRmIds(directlyStoreDOs, bigDataGeneralInfoDTOs, directlyStoreRmDOS);
        this.getRmIds(directlyExecuteDOS, bigDataGeneralInfoDTOs, directlyExecuteRmDOS);
    }

    private void getRmIds(List<? extends BaseInDO> baseInDOS, List<BigDataGeneralInfoDTO> bigDataGeneralInfoDTOs, List<Long> directlyStoreRmDOS) {
        boolean flag;
        String skuKey;
        //删选需要删除的sku,只需要根据sku和store删除即可
        for (BaseInDO baseInDO : baseInDOS) {
            flag = false;
            skuKey = baseInDO.getSkuCode();
            for (BigDataGeneralInfoDTO bigDataGeneralInfoDTO : bigDataGeneralInfoDTOs) {
                if (bigDataGeneralInfoDTO.getSkuKey().equals(skuKey)) {
                    flag = true;
                    break;
                }
            }
            //这里记录
            if (!flag) {
                directlyStoreRmDOS.add(baseInDO.getId());
            }
        }
    }

    private void getDayDO(BaseInDO baseInDO, List<DirectlyExecuteInDO> directlyExecuteInDOs, List<DirectlyStoreInDO> directlyStoreInDOs, BigDecimal sales, Date date) {
        DirectlyExecuteInDO directlyExecuteInDO = bigDataBaseConvertor.baseDOToExecuteDO(baseInDO);
        DirectlyStoreInDO directlyStoreInDO = bigDataBaseConvertor.baseDOToStoreDO(baseInDO);
        //设置日期
        directlyExecuteInDO.setFormulateDate(date);
        directlyStoreInDO.setFormulateDate(date);
        //设置预测量
        directlyExecuteInDO.setForecastSalesAmount(sales);
        directlyStoreInDO.setForecastQty(sales);
        directlyStoreInDO.setConfirmQty(sales);
        directlyStoreInDO.setLastConfirmQty(new BigDecimal("0"));
        directlyStoreInDO.setLastForecastQty(new BigDecimal("0"));
        directlyExecuteInDOs.add(directlyExecuteInDO);
        directlyStoreInDOs.add(directlyStoreInDO);
    }

    /**
     * 获取直营门店第十四天的新增实体
     *
     * @return {@link DirectlyStoreInDO}
     **/
    private DirectlyStoreInDO getNewDirectlyStore(BaseInDO baseInDO, BigDecimal sales) {
        DirectlyStoreInDO newDirectlyStoreInDO = bigDataBaseConvertor.baseDOToStoreDO(baseInDO);
        newDirectlyStoreInDO.setForecastQty(sales);
        newDirectlyStoreInDO.setConfirmQty(sales);
        newDirectlyStoreInDO.setLastForecastQty(new BigDecimal("0"));
        newDirectlyStoreInDO.setLastConfirmQty(new BigDecimal("0"));
        newDirectlyStoreInDO.setFormulateDate(day14);
        return newDirectlyStoreInDO;
    }

    /**
     * 获取直营执行第十四天的新增实体
     *
     * @return {@link DirectlyStoreInDO}
     **/
    private DirectlyExecuteInDO getNewDirectlyExecute(BaseInDO baseInDO, BigDecimal sales) {
        DirectlyExecuteInDO newDirectlyExecuteInDO = bigDataBaseConvertor.baseDOToExecuteDO(baseInDO);
        newDirectlyExecuteInDO.setForecastSalesAmount(sales);
        newDirectlyExecuteInDO.setFormulateDate(day14);
        return newDirectlyExecuteInDO;
    }

    private void setExecutePredictValue(DirectlyExecuteUpDO executeDO, BigDataGeneralInfoDTO bigDataGeneralInfoDTO) {
        //获取对应日期的预测值
        Date date = executeDO.getFormulateDate();
        if (day1.equals(date)) {
            this.setDirectExecuteValue(executeDO, bigDataGeneralInfoDTO.getSalesDayf1());
            return;
        }
        if (day2.equals(date)) {
            this.setDirectExecuteValue(executeDO, bigDataGeneralInfoDTO.getSalesDayf2());
            return;
        }
        if (day3.equals(date)) {
            this.setDirectExecuteValue(executeDO, bigDataGeneralInfoDTO.getSalesDayf3());
            return;
        }
        if (day4.equals(date)) {
            this.setDirectExecuteValue(executeDO, bigDataGeneralInfoDTO.getSalesDayf4());
            return;
        }
        if (day5.equals(date)) {
            this.setDirectExecuteValue(executeDO, bigDataGeneralInfoDTO.getSalesDayf5());
            return;
        }
        if (day6.equals(date)) {
            this.setDirectExecuteValue(executeDO, bigDataGeneralInfoDTO.getSalesDayf6());
            return;
        }
        if (day7.equals(date)) {
            this.setDirectExecuteValue(executeDO, bigDataGeneralInfoDTO.getSalesDayf7());
            return;
        }
        if (day8.equals(date)) {
            this.setDirectExecuteValue(executeDO, bigDataGeneralInfoDTO.getSalesDayf8());
            return;
        }
        if (day9.equals(date)) {
            this.setDirectExecuteValue(executeDO, bigDataGeneralInfoDTO.getSalesDayf9());
            return;
        }
        if (day10.equals(date)) {
            this.setDirectExecuteValue(executeDO, bigDataGeneralInfoDTO.getSalesDayf10());
            return;
        }
        if (day11.equals(date)) {
            this.setDirectExecuteValue(executeDO, bigDataGeneralInfoDTO.getSalesDayf11());
            return;
        }
        if (day12.equals(date)) {
            this.setDirectExecuteValue(executeDO, bigDataGeneralInfoDTO.getSalesDayf12());
            return;
        }
        if (day13.equals(date)) {
            this.setDirectExecuteValue(executeDO, bigDataGeneralInfoDTO.getSalesDayf13());
        }
    }

    /**
     * 获取（日）通用对象
     *
     * @param skuKey
     * @param storeInfo
     * @param skuCodeName
     * @param categoryInfo
     * @return void
     **/
    private BaseInDO createGeneralDayInDO(String skuKey, StoreInfoDTO storeInfo, Map<String, SkuInfoDTO> skuCodeName, Map<Integer, List<CategorySimpleDTO>> categoryInfo) {
        BaseInDO baseInDO = new BaseInDO();
        baseInDO.setOpSign(opSign);
        //设置渠道信息
        baseInDO.setChannelCode(BigDataChannelEnum.STORE_DIRECT.getChannelCode());
        baseInDO.setChannelName(BigDataChannelEnum.STORE_DIRECT.getChannelName());
        //设置省市区 门店
        this.setGeneralAreaValue(baseInDO, storeInfo);
        //设置大中小品类
        baseInDO.setSkuCode(skuKey);
        if (skuCodeName.get(skuKey) != null) {
            SkuInfoDTO skuInfoDTO = skuCodeName.get(skuKey);
            baseInDO.setSkuName(skuInfoDTO.getName());
            List<CategorySimpleDTO> categorySimpleDTOS = categoryInfo.get(skuInfoDTO.getCategoryId());
            if (!CollectionUtils.isEmpty(categorySimpleDTOS)) {
                BaseInDO finalDirectlyExecuteInDO = baseInDO;
                categorySimpleDTOS.forEach(subItem -> this.setGeneralCategoryValue(subItem, finalDirectlyExecuteInDO));
            }
        }
        return baseInDO;
    }

    private void setStorePredictValue(DirectlyStoreUpDO storeDO, BigDataGeneralInfoDTO bigDataGeneralInfoDTO) {
        //获取对应日期的预测值
        Date date = storeDO.getFormulateDate();
        if (day1.equals(date)) {
            this.setDirectStoreValue(storeDO, bigDataGeneralInfoDTO.getSalesDayf1());
            return;
        }
        if (day2.equals(date)) {
            this.setDirectStoreValue(storeDO, bigDataGeneralInfoDTO.getSalesDayf2());
            return;
        }
        if (day3.equals(date)) {
            this.setDirectStoreValue(storeDO, bigDataGeneralInfoDTO.getSalesDayf3());
            return;
        }
        if (day4.equals(date)) {
            this.setDirectStoreValue(storeDO, bigDataGeneralInfoDTO.getSalesDayf4());
            return;
        }
        if (day5.equals(date)) {
            this.setDirectStoreValue(storeDO, bigDataGeneralInfoDTO.getSalesDayf5());
            return;
        }
        if (day6.equals(date)) {
            this.setDirectStoreValue(storeDO, bigDataGeneralInfoDTO.getSalesDayf6());
            return;
        }
        if (day7.equals(date)) {
            this.setDirectStoreValue(storeDO, bigDataGeneralInfoDTO.getSalesDayf7());
            return;
        }
        if (day8.equals(date)) {
            this.setDirectStoreValue(storeDO, bigDataGeneralInfoDTO.getSalesDayf8());
            return;
        }
        if (day9.equals(date)) {
            this.setDirectStoreValue(storeDO, bigDataGeneralInfoDTO.getSalesDayf9());
            return;
        }
        if (day10.equals(date)) {
            this.setDirectStoreValue(storeDO, bigDataGeneralInfoDTO.getSalesDayf10());
            return;
        }
        if (day11.equals(date)) {
            this.setDirectStoreValue(storeDO, bigDataGeneralInfoDTO.getSalesDayf11());
            return;
        }
        if (day12.equals(date)) {
            this.setDirectStoreValue(storeDO, bigDataGeneralInfoDTO.getSalesDayf12());
            return;
        }
        if (day13.equals(date)) {
            this.setDirectStoreValue(storeDO, bigDataGeneralInfoDTO.getSalesDayf13());
        }
    }

    private void setDirectStoreValue(DirectlyStoreUpDO storeDO, BigDecimal sales) {
        storeDO.setLastForecastQty(storeDO.getForecastQty());
        storeDO.setForecastQty(sales);
        storeDO.setLastConfirmQty(storeDO.getConfirmQty());
        storeDO.setConfirmQty(sales);
    }

    private void setDirectExecuteValue(DirectlyExecuteUpDO executeDO, BigDecimal sales) {
        executeDO.setForecastSalesAmount(sales);
    }

    /**
     * 获取（日）通用对象
     *
     * @param skuKey
     * @param storeInfo
     * @param skuCodeName
     * @param categoryInfo
     * @return void
     **/
    private void setGeneralInfo(BaseInDO baseInDO, String skuKey, StoreInfoDTO storeInfo, Map<String, SkuInfoDTO> skuCodeName, Map<Integer, List<CategorySimpleDTO>> categoryInfo) {
        baseInDO.setOpSign(opSign);
        //设置渠道信息
        baseInDO.setChannelCode(BigDataChannelEnum.STORE_DIRECT.getChannelCode());
        baseInDO.setChannelName(BigDataChannelEnum.STORE_DIRECT.getChannelName());
        //设置省市区 门店
        this.setGeneralAreaValue(baseInDO, storeInfo);
        //设置大中小品类
        baseInDO.setSkuCode(skuKey);
        if (skuCodeName.get(skuKey) != null) {
            SkuInfoDTO skuInfoDTO = skuCodeName.get(skuKey);
            baseInDO.setSkuName(skuInfoDTO.getName());
            List<CategorySimpleDTO> categorySimpleDTOS = categoryInfo.get(skuInfoDTO.getCategoryId());
            if (!CollectionUtils.isEmpty(categorySimpleDTOS)) {
                BaseInDO finalDirectlyExecuteInDO = baseInDO;
                categorySimpleDTOS.forEach(subItem -> this.setGeneralCategoryValue(subItem, finalDirectlyExecuteInDO));
            }
        }
    }

    /**
     * 设置通用属性 设置品类
     *
     * @param subItem
     * @param baseInDO
     * @return void
     **/
    private void setGeneralCategoryValue(CategorySimpleDTO subItem, BaseInDO baseInDO) {
        Integer level = subItem.getCategoryLevel();
        switch (level) {
            case 2:
                baseInDO.setPriCategoryCode(String.valueOf(subItem.getCategoryCode()));
                baseInDO.setPriCategoryName(subItem.getCategoryName());
                break;
            case 3:
                baseInDO.setSecCategoryCode(String.valueOf(subItem.getCategoryCode()));
                baseInDO.setSecCategoryName(subItem.getCategoryName());
                break;
            case 4:
                baseInDO.setTerCategoryCode(String.valueOf(subItem.getCategoryCode()));
                baseInDO.setTerCategoryName(subItem.getCategoryName());
                break;
            default:
        }
    }

    /**
     * 设置通用属性 设置省市区 门店
     *
     * @param baseInDO
     * @param storeInfo
     * @return void
     **/
    private void setGeneralAreaValue(BaseInDO baseInDO, StoreInfoDTO storeInfo) {
        baseInDO.setProvinceCode(storeInfo.getProvinceCode());
        baseInDO.setProvinceName(storeInfo.getProvinceName());
        baseInDO.setCityCode(storeInfo.getCityCode());
        baseInDO.setCityName(storeInfo.getCityName());
        baseInDO.setCountyCode(storeInfo.getAreaCode());
        baseInDO.setCountyName(storeInfo.getAreaName());
        baseInDO.setStoreCode(storeInfo.getCode());
        baseInDO.setStoreName(storeInfo.getName());
        baseInDO.setProvinceCode(storeInfo.getProvinceCode());
        baseInDO.setProvinceName(storeInfo.getProvinceName());
        baseInDO.setCityCode(storeInfo.getCityCode());
        baseInDO.setCityName(storeInfo.getCityName());
        baseInDO.setCountyCode(storeInfo.getAreaCode());
        baseInDO.setCountyName(storeInfo.getAreaName());
        baseInDO.setStoreCode(storeInfo.getCode());
        baseInDO.setStoreName(storeInfo.getName());
    }

    private void getDayAndWeekResult(StoreInfoDTO storeInfo, List<BigDataGeneralInfoDTO> bigDataGeneralInfoDTOs, List<DirectlyExecuteInDO> directlyExecuteInDOs, List<DirectlyExecuteUpDO> directlyExecuteUpDOS, List<DirectlyStoreInDO> directlyStoreInDOs, List<DirectlyStoreUpDO> directlyStoreUpDOS, List<DirectlyAccuracyInDO> directlyAccuracyInDOs, List<DirectlyAccuracyUpDO> directlyAccuracyUpDOS, List<DirectlyDifferinInDO> directlyDifferinInDOs, List<DirectlyDifferinUpDO> directlyDifferinUpDOs, List<DirectlyInDO> directlyInDOs, List<DirectlyUpDO> directlyUpDOs, List<Long> directlyExecuteRmDOS, List<Long> directlyRmDOs, List<Long> directlyStoreRmDOS, List<Long> directlyAccuracyRmDOs, List<Long> directlyDifferinRmDOs) {
        //直营预测——门店 根据门店和日期获取所有需要更新的数据（默认为13天数据，今日起）
        List<DirectlyStoreUpDO> directlyStoreDOs = directlyStoreRepository.listUpByStoreAndDate(storeInfo.getCode(), BigDataCacheUtil.dayStartDate, BigDataCacheUtil.dayUpEndDate);
        //直营预测执行
        List<DirectlyExecuteUpDO> directlyExecuteDOS = directlyExecuteRepository.listUpByStoreAndDate(storeInfo.getCode(), BigDataCacheUtil.dayStartDate, BigDataCacheUtil.dayUpEndDate);
        //直营准确率
        List<DirectlyAccuracyUpDO> directlyAccuracyDOS = salesPlanDirectlyAccuracyRepository.listUpByStoreAndDate(storeInfo.getCode(), BigDataCacheUtil.weekStartDate, BigDataCacheUtil.weekUpEndDate);
        //直营差异
        List<DirectlyDifferinUpDO> directlyDifferinDOS = salePlanDirectlyDifferinRepository.listUpByStoreAndDate(storeInfo.getCode(), BigDataCacheUtil.weekStartDate, BigDataCacheUtil.weekUpEndDate);
        //直营预测
        List<DirectlyUpDO> directlyDOs = salesPlanDirectlyRepository.listUpByStoreAndDate(storeInfo.getCode(), BigDataCacheUtil.weekStartDate, BigDataCacheUtil.weekUpEndDate);
        if (CollectionUtils.isEmpty(directlyStoreDOs)) {
            directlyStoreDOs = new ArrayList<>(1);
        }
        if (CollectionUtils.isEmpty(directlyExecuteDOS)) {
            directlyExecuteDOS = new ArrayList<>(1);
        }
        if (CollectionUtils.isEmpty(directlyAccuracyDOS)) {
            directlyAccuracyDOS = new ArrayList<>(1);
        }
        if (CollectionUtils.isEmpty(directlyDifferinDOS)) {
            directlyDifferinDOS = new ArrayList<>(1);
        }
        if (CollectionUtils.isEmpty(directlyDOs)) {
            directlyDOs = new ArrayList<>(1);
        }
        //查询sku信息
        List<SkuInfoDTO> skuInfoDTOS = itemCoreFacade.skuListBySkuCodes(bigDataGeneralInfoDTOs.stream().map(BigDataGeneralInfoDTO::getSkuKey).distinct().collect(Collectors.toList()));
        Map<String, SkuInfoDTO> skuCodeName = this.getSkuInfo(skuInfoDTOS);
        Map<Integer, List<CategorySimpleDTO>> categoryInfo = this.getCategoryInfo(skuInfoDTOS);
        int countStore;
        int countDirect;
        List<DirectlyStoreUpDO> tmpStore;
        List<DirectlyUpDO> tmpDirect;
        //新增sku
        String skuKey;
        BaseInDO baseInDO;
        for (BigDataGeneralInfoDTO bigDataGeneralInfoDTO : bigDataGeneralInfoDTOs) {
            skuKey = bigDataGeneralInfoDTO.getSkuKey();
            //直营预测————门店
            tmpStore = new ArrayList<>();
            tmpDirect = new ArrayList<>();
            countStore = 0;
            countDirect = 0;
            for (DirectlyStoreUpDO storeDO : directlyStoreDOs) {
                //如果是同一条sku,默认取十三天为更新数据，第十四条为新增数据 存入集合中
                if (skuKey.equals(storeDO.getSkuCode())) {
                    //更新其同用属性（区域，品类）
                    this.setGeneralInfo(storeDO, skuKey, storeInfo, skuCodeName, categoryInfo);
                    //更新其预测值
                    this.setStorePredictValue(storeDO, bigDataGeneralInfoDTO);
                    tmpStore.add(storeDO);
                    countStore++;
                }
            }
            //如果已存在数据含有该条sku，直营预测执行  获得需要更新的十三天数据，门店和执行新增第十四日数据
            baseInDO = this.createGeneralDayInDO(skuKey, storeInfo, skuCodeName, categoryInfo);
            if (countStore == 13) {
                directlyStoreUpDOS.addAll(tmpStore);
                for (DirectlyExecuteUpDO executeDO : directlyExecuteDOS) {
                    //如果是同一条sku,默认取十三天为更新数据，第十四条为新增数据 存入集合中
                    if (skuKey.equals(executeDO.getSkuCode())) {
                        //更新其同用属性（区域，品类）
                        this.setGeneralInfo(executeDO, skuKey, storeInfo, skuCodeName, categoryInfo);
                        //更新其预测值
                        this.setExecutePredictValue(executeDO, bigDataGeneralInfoDTO);
                        directlyExecuteUpDOS.add(executeDO);
                    }
                }
                //加入第十四天数据，门店和执行
                directlyStoreInDOs.add(this.getNewDirectlyStore(baseInDO, bigDataGeneralInfoDTO.getSalesDayf14()));
                directlyExecuteInDOs.add(this.getNewDirectlyExecute(baseInDO, bigDataGeneralInfoDTO.getSalesDayf14()));
            } else {
                //处理消失过的sku
                if (countStore != 0) {
                    for (DirectlyExecuteUpDO executeDO : directlyExecuteDOS) {
                        //如果是同一条sku,默认取十三天为更新数据，第十四条为新增数据 存入集合中
                        if (skuKey.equals(executeDO.getSkuCode())) {
                            directlyExecuteRmDOS.add(executeDO.getId());
                        }
                    }
                    directlyStoreRmDOS.addAll(tmpStore.stream().map(DirectlyStoreUpDO::getId).collect(Collectors.toList()));
                }
                //如果不存在该条sku,两张表都做新增操作
                this.getDayDO(baseInDO, directlyExecuteInDOs, directlyStoreInDOs, bigDataGeneralInfoDTO.getSalesDayf1(), day1);
                this.getDayDO(baseInDO, directlyExecuteInDOs, directlyStoreInDOs, bigDataGeneralInfoDTO.getSalesDayf2(), day2);
                this.getDayDO(baseInDO, directlyExecuteInDOs, directlyStoreInDOs, bigDataGeneralInfoDTO.getSalesDayf3(), day3);
                this.getDayDO(baseInDO, directlyExecuteInDOs, directlyStoreInDOs, bigDataGeneralInfoDTO.getSalesDayf4(), day4);
                this.getDayDO(baseInDO, directlyExecuteInDOs, directlyStoreInDOs, bigDataGeneralInfoDTO.getSalesDayf5(), day5);
                this.getDayDO(baseInDO, directlyExecuteInDOs, directlyStoreInDOs, bigDataGeneralInfoDTO.getSalesDayf6(), day6);
                this.getDayDO(baseInDO, directlyExecuteInDOs, directlyStoreInDOs, bigDataGeneralInfoDTO.getSalesDayf7(), day7);
                this.getDayDO(baseInDO, directlyExecuteInDOs, directlyStoreInDOs, bigDataGeneralInfoDTO.getSalesDayf8(), day8);
                this.getDayDO(baseInDO, directlyExecuteInDOs, directlyStoreInDOs, bigDataGeneralInfoDTO.getSalesDayf9(), day9);
                this.getDayDO(baseInDO, directlyExecuteInDOs, directlyStoreInDOs, bigDataGeneralInfoDTO.getSalesDayf10(), day10);
                this.getDayDO(baseInDO, directlyExecuteInDOs, directlyStoreInDOs, bigDataGeneralInfoDTO.getSalesDayf11(), day11);
                this.getDayDO(baseInDO, directlyExecuteInDOs, directlyStoreInDOs, bigDataGeneralInfoDTO.getSalesDayf12(), day12);
                this.getDayDO(baseInDO, directlyExecuteInDOs, directlyStoreInDOs, bigDataGeneralInfoDTO.getSalesDayf13(), day13);
                this.getDayDO(baseInDO, directlyExecuteInDOs, directlyStoreInDOs, bigDataGeneralInfoDTO.getSalesDayf14(), day14);
            }
            //处理周数据-直营预测
            for (DirectlyUpDO directlyDO : directlyDOs) {
                //如果是同一条sku,默认取十三天为更新数据，第十四条为新增数据 存入集合中
                if (skuKey.equals(directlyDO.getSkuCode())) {
                    //更新其同用属性（区域，品类）
                    this.setGeneralInfo(directlyDO, skuKey, storeInfo, skuCodeName, categoryInfo);
                    //更新其预测值
                    this.setDirectlyPredictValue(directlyDO, bigDataGeneralInfoDTO);
                    tmpDirect.add(directlyDO);
                    countDirect++;
                }
            }
            if (countDirect == 12) {
                directlyUpDOs.addAll(tmpDirect);
                for (DirectlyAccuracyUpDO directlyAccuracyDO : directlyAccuracyDOS) {
                    //如果是同一条sku,默认取十三天为更新数据，第十四条为新增数据 存入集合中
                    if (skuKey.equals(directlyAccuracyDO.getSkuCode())) {
                        //更新其同用属性（区域，品类）
                        this.setGeneralInfo(directlyAccuracyDO, skuKey, storeInfo, skuCodeName, categoryInfo);
                        //更新其预测值
                        this.setDirectlyAccuracyPredictValue(directlyAccuracyDO, bigDataGeneralInfoDTO);
                        directlyAccuracyUpDOS.add(directlyAccuracyDO);
                    }
                }
                for (DirectlyDifferinUpDO directlyDifferinUpDO : directlyDifferinDOS) {
                    //如果是同一条sku,默认取十三天为更新数据，第十四条为新增数据 存入集合中
                    if (skuKey.equals(directlyDifferinUpDO.getSkuCode())) {
                        //更新其同用属性（区域，品类）
                        this.setGeneralInfo(directlyDifferinUpDO, skuKey, storeInfo, skuCodeName, categoryInfo);
                        //更新其预测值
                        this.setDirectlyDifferPredictValue(directlyDifferinUpDO, bigDataGeneralInfoDTO);
                        directlyDifferinUpDOs.add(directlyDifferinUpDO);
                    }
                }
                directlyInDOs.add(this.getNewDirectly(baseInDO, bigDataGeneralInfoDTO.getSalesWeekf13()));
                //加入第十四天数据，门店和执行
                directlyAccuracyInDOs.add(this.getNewDirectlyAccuracy(baseInDO, bigDataGeneralInfoDTO.getSalesWeekf13()));
                directlyDifferinInDOs.add(this.getNewDirectlyDiffer(baseInDO, bigDataGeneralInfoDTO.getSalesWeekf13()));
            } else {
                //处理消失过的sku
                if (countDirect != 0) {
                    for (DirectlyAccuracyUpDO directlyAccuracyDO : directlyAccuracyDOS) {
                        //如果是同一条sku,默认取十三天为更新数据，第十四条为新增数据 存入集合中
                        if (skuKey.equals(directlyAccuracyDO.getSkuCode())) {
                            directlyAccuracyRmDOs.add(directlyAccuracyDO.getId());
                        }
                    }
                    for (DirectlyDifferinUpDO directlyDifferinUpDO : directlyDifferinDOS) {
                        //如果是同一条sku,默认取十三天为更新数据，第十四条为新增数据 存入集合中
                        if (skuKey.equals(directlyDifferinUpDO.getSkuCode())) {
                            directlyDifferinRmDOs.add(directlyDifferinUpDO.getId());
                        }
                    }
                    directlyRmDOs.addAll(tmpDirect.stream().map(DirectlyUpDO::getId).collect(Collectors.toList()));
                }
                //如果不存在该条sku,两张表都做新增操作
                this.getWeekDO(baseInDO, directlyAccuracyInDOs, directlyDifferinInDOs, directlyInDOs, bigDataGeneralInfoDTO.getSalesWeekf1(), startDate1, endDate1);
                this.getWeekDO(baseInDO, directlyAccuracyInDOs, directlyDifferinInDOs, directlyInDOs, bigDataGeneralInfoDTO.getSalesWeekf2(), startDate2, endDate2);
                this.getWeekDO(baseInDO, directlyAccuracyInDOs, directlyDifferinInDOs, directlyInDOs, bigDataGeneralInfoDTO.getSalesWeekf3(), startDate3, endDate3);
                this.getWeekDO(baseInDO, directlyAccuracyInDOs, directlyDifferinInDOs, directlyInDOs, bigDataGeneralInfoDTO.getSalesWeekf4(), startDate4, endDate4);
                this.getWeekDO(baseInDO, directlyAccuracyInDOs, directlyDifferinInDOs, directlyInDOs, bigDataGeneralInfoDTO.getSalesWeekf5(), startDate5, endDate5);
                this.getWeekDO(baseInDO, directlyAccuracyInDOs, directlyDifferinInDOs, directlyInDOs, bigDataGeneralInfoDTO.getSalesWeekf6(), startDate6, endDate6);
                this.getWeekDO(baseInDO, directlyAccuracyInDOs, directlyDifferinInDOs, directlyInDOs, bigDataGeneralInfoDTO.getSalesWeekf7(), startDate7, endDate7);
                this.getWeekDO(baseInDO, directlyAccuracyInDOs, directlyDifferinInDOs, directlyInDOs, bigDataGeneralInfoDTO.getSalesWeekf8(), startDate8, endDate8);
                this.getWeekDO(baseInDO, directlyAccuracyInDOs, directlyDifferinInDOs, directlyInDOs, bigDataGeneralInfoDTO.getSalesWeekf9(), startDate9, endDate9);
                this.getWeekDO(baseInDO, directlyAccuracyInDOs, directlyDifferinInDOs, directlyInDOs, bigDataGeneralInfoDTO.getSalesWeekf10(), startDate10, endDate10);
                this.getWeekDO(baseInDO, directlyAccuracyInDOs, directlyDifferinInDOs, directlyInDOs, bigDataGeneralInfoDTO.getSalesWeekf11(), startDate11, endDate11);
                this.getWeekDO(baseInDO, directlyAccuracyInDOs, directlyDifferinInDOs, directlyInDOs, bigDataGeneralInfoDTO.getSalesWeekf12(), startDate12, endDate12);
                this.getWeekDO(baseInDO, directlyAccuracyInDOs, directlyDifferinInDOs, directlyInDOs, bigDataGeneralInfoDTO.getSalesWeekf13(), startDate13, endDate13);
            }
        }
        //获取需要删除的sku（根据id删除）
        this.getRmIds(directlyStoreDOs, bigDataGeneralInfoDTOs, directlyStoreRmDOS);
        this.getRmIds(directlyExecuteDOS, bigDataGeneralInfoDTOs, directlyExecuteRmDOS);
        this.getRmIds(directlyAccuracyDOS, bigDataGeneralInfoDTOs, directlyAccuracyRmDOs);
        this.getRmIds(directlyDifferinDOS, bigDataGeneralInfoDTOs, directlyDifferinRmDOs);
        this.getRmIds(directlyDOs, bigDataGeneralInfoDTOs, directlyRmDOs);
    }

    private void getWeekDO(BaseInDO baseInDO, List<DirectlyAccuracyInDO> directlyAccuracyInDOs, List<DirectlyDifferinInDO> directlyDifferinInDOs, List<DirectlyInDO> directlyInDOs, BigDecimal sales, Date startDate, Date endDate) {
        DirectlyAccuracyInDO directlyAccuracyInDO = bigDataBaseConvertor.baseDOToAccuracyDO(baseInDO);
        DirectlyDifferinInDO directlyDifferinInDO = bigDataBaseConvertor.baseDOToDifferDO(baseInDO);
        DirectlyInDO directlyInDO = bigDataBaseConvertor.baseDOToDirectDO(baseInDO);
        //设置日期
        directlyAccuracyInDO.setPlanStartDate(startDate);
        directlyAccuracyInDO.setPlanEndDate(endDate);
        directlyDifferinInDO.setPlanStartDate(startDate);
        directlyDifferinInDO.setPlanEndDate(endDate);
        directlyInDO.setPlanStartDate(startDate);
        directlyInDO.setPlanEndDate(endDate);
        //设置预测量
        directlyAccuracyInDO.setPredictedQty(sales);
        directlyDifferinInDO.setSalesForecastQty(sales);
        directlyInDO.setForecastQty(sales);
        //加默认值
        directlyInDO.setLastForecastQty(new BigDecimal("0"));
        directlyAccuracyInDOs.add(directlyAccuracyInDO);
        directlyDifferinInDOs.add(directlyDifferinInDO);
        directlyInDOs.add(directlyInDO);
    }

    private DirectlyDifferinInDO getNewDirectlyDiffer(BaseInDO baseInDO, BigDecimal sales) {
        DirectlyDifferinInDO directlyDifferinInDO = bigDataBaseConvertor.baseDOToDifferDO(baseInDO);
        directlyDifferinInDO.setSalesForecastQty(sales);
        directlyDifferinInDO.setPlanStartDate(startDate13);
        directlyDifferinInDO.setPlanEndDate(endDate13);
        return directlyDifferinInDO;
    }

    private DirectlyAccuracyInDO getNewDirectlyAccuracy(BaseInDO baseInDO, BigDecimal sales) {
        DirectlyAccuracyInDO directlyAccuracyInDO = bigDataBaseConvertor.baseDOToAccuracyDO(baseInDO);
        directlyAccuracyInDO.setPredictedQty(sales);
        directlyAccuracyInDO.setPlanStartDate(startDate13);
        directlyAccuracyInDO.setPlanEndDate(endDate13);
        return directlyAccuracyInDO;
    }

    /**
     * 获取直营预测第十四周的新增实体
     *
     * @return {@link DirectlyStoreInDO}
     **/
    private DirectlyInDO getNewDirectly(BaseInDO baseInDO, BigDecimal sales) {
        DirectlyInDO directlyInDO = bigDataBaseConvertor.baseDOToDirectDO(baseInDO);
        directlyInDO.setForecastQty(sales);
        directlyInDO.setLastForecastQty(new BigDecimal("0"));
        directlyInDO.setPlanStartDate(startDate13);
        directlyInDO.setPlanEndDate(endDate13);
        return directlyInDO;
    }

    private void setDirectlyPredictValue(DirectlyUpDO directlyDO, BigDataGeneralInfoDTO bigDataGeneralInfoDTO) {
        //获取对应日期的预测值
        Date startDate = directlyDO.getPlanStartDate();
        if (startDate1.equals(startDate)) {
            this.setDirectValue(directlyDO, bigDataGeneralInfoDTO.getSalesWeekf1());
            return;
        }
        if (startDate2.equals(startDate)) {
            this.setDirectValue(directlyDO, bigDataGeneralInfoDTO.getSalesDayf2());
            return;
        }
        if (startDate3.equals(startDate)) {
            this.setDirectValue(directlyDO, bigDataGeneralInfoDTO.getSalesDayf3());
            return;
        }
        if (startDate4.equals(startDate)) {
            this.setDirectValue(directlyDO, bigDataGeneralInfoDTO.getSalesDayf4());
            return;
        }
        if (startDate5.equals(startDate)) {
            this.setDirectValue(directlyDO, bigDataGeneralInfoDTO.getSalesDayf5());
            return;
        }
        if (startDate6.equals(startDate)) {
            this.setDirectValue(directlyDO, bigDataGeneralInfoDTO.getSalesDayf6());
            return;
        }
        if (startDate7.equals(startDate)) {
            this.setDirectValue(directlyDO, bigDataGeneralInfoDTO.getSalesDayf7());
            return;
        }
        if (startDate8.equals(startDate)) {
            this.setDirectValue(directlyDO, bigDataGeneralInfoDTO.getSalesDayf8());
            return;
        }
        if (startDate9.equals(startDate)) {
            this.setDirectValue(directlyDO, bigDataGeneralInfoDTO.getSalesDayf9());
            return;
        }
        if (startDate10.equals(startDate)) {
            this.setDirectValue(directlyDO, bigDataGeneralInfoDTO.getSalesDayf10());
            return;
        }
        if (startDate11.equals(startDate)) {
            this.setDirectValue(directlyDO, bigDataGeneralInfoDTO.getSalesDayf11());
            return;
        }
        if (startDate12.equals(startDate)) {
            this.setDirectValue(directlyDO, bigDataGeneralInfoDTO.getSalesDayf12());
        }
    }

    private void setDirectlyAccuracyPredictValue(DirectlyAccuracyUpDO directlyAccuracyDO, BigDataGeneralInfoDTO bigDataGeneralInfoDTO) {
        //获取对应日期的预测值
        Date startDate = directlyAccuracyDO.getPlanStartDate();
        if (startDate1.equals(startDate)) {
            this.setDirectAccuracyValue(directlyAccuracyDO, bigDataGeneralInfoDTO.getSalesWeekf1());
            return;
        }
        if (startDate2.equals(startDate)) {
            this.setDirectAccuracyValue(directlyAccuracyDO, bigDataGeneralInfoDTO.getSalesDayf2());
            return;
        }
        if (startDate3.equals(startDate)) {
            this.setDirectAccuracyValue(directlyAccuracyDO, bigDataGeneralInfoDTO.getSalesDayf3());
            return;
        }
        if (startDate4.equals(startDate)) {
            this.setDirectAccuracyValue(directlyAccuracyDO, bigDataGeneralInfoDTO.getSalesDayf4());
            return;
        }
        if (startDate5.equals(startDate)) {
            this.setDirectAccuracyValue(directlyAccuracyDO, bigDataGeneralInfoDTO.getSalesDayf5());
            return;
        }
        if (startDate6.equals(startDate)) {
            this.setDirectAccuracyValue(directlyAccuracyDO, bigDataGeneralInfoDTO.getSalesDayf6());
            return;
        }
        if (startDate7.equals(startDate)) {
            this.setDirectAccuracyValue(directlyAccuracyDO, bigDataGeneralInfoDTO.getSalesDayf7());
            return;
        }
        if (startDate8.equals(startDate)) {
            this.setDirectAccuracyValue(directlyAccuracyDO, bigDataGeneralInfoDTO.getSalesDayf8());
            return;
        }
        if (startDate9.equals(startDate)) {
            this.setDirectAccuracyValue(directlyAccuracyDO, bigDataGeneralInfoDTO.getSalesDayf9());
            return;
        }
        if (startDate10.equals(startDate)) {
            this.setDirectAccuracyValue(directlyAccuracyDO, bigDataGeneralInfoDTO.getSalesDayf10());
            return;
        }
        if (startDate11.equals(startDate)) {
            this.setDirectAccuracyValue(directlyAccuracyDO, bigDataGeneralInfoDTO.getSalesDayf11());
            return;
        }
        if (startDate12.equals(startDate)) {
            this.setDirectAccuracyValue(directlyAccuracyDO, bigDataGeneralInfoDTO.getSalesDayf12());
        }
    }

    private void setDirectlyDifferPredictValue(DirectlyDifferinUpDO directlyDifferinUpDO, BigDataGeneralInfoDTO bigDataGeneralInfoDTO) {
        //获取对应日期的预测值
        Date startDate = directlyDifferinUpDO.getPlanStartDate();
        if (startDate1.equals(startDate)) {
            this.setDirectDifferValue(directlyDifferinUpDO, bigDataGeneralInfoDTO.getSalesWeekf1());
            return;
        }
        if (startDate2.equals(startDate)) {
            this.setDirectDifferValue(directlyDifferinUpDO, bigDataGeneralInfoDTO.getSalesDayf2());
            return;
        }
        if (startDate3.equals(startDate)) {
            this.setDirectDifferValue(directlyDifferinUpDO, bigDataGeneralInfoDTO.getSalesDayf3());
            return;
        }
        if (startDate4.equals(startDate)) {
            this.setDirectDifferValue(directlyDifferinUpDO, bigDataGeneralInfoDTO.getSalesDayf4());
            return;
        }
        if (startDate5.equals(startDate)) {
            this.setDirectDifferValue(directlyDifferinUpDO, bigDataGeneralInfoDTO.getSalesDayf5());
            return;
        }
        if (startDate6.equals(startDate)) {
            this.setDirectDifferValue(directlyDifferinUpDO, bigDataGeneralInfoDTO.getSalesDayf6());
            return;
        }
        if (startDate7.equals(startDate)) {
            this.setDirectDifferValue(directlyDifferinUpDO, bigDataGeneralInfoDTO.getSalesDayf7());
            return;
        }
        if (startDate8.equals(startDate)) {
            this.setDirectDifferValue(directlyDifferinUpDO, bigDataGeneralInfoDTO.getSalesDayf8());
            return;
        }
        if (startDate9.equals(startDate)) {
            this.setDirectDifferValue(directlyDifferinUpDO, bigDataGeneralInfoDTO.getSalesDayf9());
            return;
        }
        if (startDate10.equals(startDate)) {
            this.setDirectDifferValue(directlyDifferinUpDO, bigDataGeneralInfoDTO.getSalesDayf10());
            return;
        }
        if (startDate11.equals(startDate)) {
            this.setDirectDifferValue(directlyDifferinUpDO, bigDataGeneralInfoDTO.getSalesDayf11());
            return;
        }
        if (startDate12.equals(startDate)) {
            this.setDirectDifferValue(directlyDifferinUpDO, bigDataGeneralInfoDTO.getSalesDayf12());
        }
    }

    private void setDirectValue(DirectlyUpDO directlyDO, BigDecimal sales) {
        directlyDO.setLastForecastQty(directlyDO.getForecastQty());
        directlyDO.setForecastQty(sales);
    }

    private void setDirectAccuracyValue(DirectlyAccuracyUpDO directlyAccuracyDO, BigDecimal sales) {
        directlyAccuracyDO.setPredictedQty(sales);
    }

    private void setDirectDifferValue(DirectlyDifferinUpDO directlyDifferinUpDO, BigDecimal sales) {
        directlyDifferinUpDO.setSalesForecastQty(sales);
    }

    /**
     * 根据skuInfo获取sku-map信息
     *
     * @param skuInfoDTOS
     * @return void
     **/
    private Map<String, SkuInfoDTO> getSkuInfo(List<SkuInfoDTO> skuInfoDTOS) {
        //根据skuCodes查询skuInfo
        Map<String, SkuInfoDTO> skuCodeName = new HashMap<>();
        if (!CollectionUtils.isEmpty(skuInfoDTOS)) {
            skuCodeName = skuInfoDTOS.stream().collect(Collectors.toMap(SkuInfoDTO::getSkuCode, item -> item));
        }
        return skuCodeName;
    }

    /**
     * 根据skuInfo获取sku品类信息
     *
     * @param skuInfoDTOS
     * @return void
     **/
    private Map<Integer, List<CategorySimpleDTO>> getCategoryInfo(List<SkuInfoDTO> skuInfoDTOS) {
        Map<Integer, List<CategorySimpleDTO>> categoryInfo = new HashMap<>();
        if (!CollectionUtils.isEmpty(skuInfoDTOS)) {
            List<CategorySimpleDTO> categorySimpleDTOS = itemCoreFacade.getAllCategoryByCategoryId(skuInfoDTOS.stream().map(SkuInfoDTO::getCategoryId).distinct().collect(Collectors.toList()));
            categoryInfo = categorySimpleDTOS.stream().collect(Collectors.toMap(CategorySimpleDTO::getId, CategorySimpleDTO::getParentCategoryDTOList));
        }
        return categoryInfo;
    }

    /**
     * 递归分页获取数据
     *
     * @param bigDataGeneralQueryBaseDTO
     * @param bigDataGeneralInfoDTOs
     * @return void
     **/
    private void getBigDataGeneralInfo(BigDataGeneralQueryBaseDTO bigDataGeneralQueryBaseDTO, List<BigDataGeneralInfoDTO> bigDataGeneralInfoDTOs) {
        bigDataGeneralQueryBaseDTO.setPageNo(bigDataGeneralQueryBaseDTO.getPageNo() + 1);
        List<BigDataGeneralInfoDTO> itemDTOS = cprfCoreFacade.getDayPredictReplenishment(bigDataGeneralQueryBaseDTO);
        if (!CollectionUtils.isEmpty(itemDTOS)) {
            bigDataGeneralInfoDTOs.addAll(itemDTOS);
            if (itemDTOS.size() == CommonConstants.BIG_DATA_PAGE_SIZE) {
                this.getBigDataGeneralInfo(bigDataGeneralQueryBaseDTO, bigDataGeneralInfoDTOs);
            }
        }
    }

    /**
     * 大数据查询实体
     *
     * @param storeCode
     * @param nowDateStr
     * @return {@link BigDataGeneralQueryBaseDTO}
     **/
    private BigDataGeneralQueryBaseDTO getGeneralQueryBaseDTO(String storeCode, String nowDateStr) {
        BigDataGeneralQueryBaseDTO bigDataGeneralQueryBaseDTO = new BigDataGeneralQueryBaseDTO();
        bigDataGeneralQueryBaseDTO.setStartDate(nowDateStr);
        bigDataGeneralQueryBaseDTO.setEndDate(nowDateStr);
        bigDataGeneralQueryBaseDTO.setStore(storeCode);
        //TODO 每页查询条数暂定为5000条
        bigDataGeneralQueryBaseDTO.setPageNo(0);
        bigDataGeneralQueryBaseDTO.setPageSize(CommonConstants.BIG_DATA_PAGE_SIZE);
        return bigDataGeneralQueryBaseDTO;
    }

    private void initCacheData() {
        Date date = new Date();
        this.validWeekJob = validWeekJob(date);
        //获取日十四天日期
        BigDataCacheUtil.injectDayCache(date);
        BigDataCacheUtil.injectWeekCache(date);
        //数据标识
        IdWorker idWorker = new IdWorker();
        opSign = "" + idWorker.getId();
    }

    /**
     * 判断是否需要触发周数据任务（默认为每周一才能触发）
     *
     * @param
     * @return {@link boolean}
     **/
    private boolean validWeekJob(Date date) {
        return DateUtil.dayOfWeek(date) == 2;
    }

    /**
     * 插入操作日志
     *
     * @param
     * @return void
     **/
    private void writeOperateLog(Long time) {
        //插入该批次数据日志
        List<OperationLogRecordDO> operationLogRecordDOs = new ArrayList<>(6);
        operationLogRecordDOs.add(OperationLogRecordUtil.getBigDataOperationLog(opSign, OperationDataEnum.DIRECTLY_EXECUTE.getTableType(), time + "ms", OpContentEnum.BIG_DATA_OPERATION_DIRECT_LOG.getIndex().toString(),OpContentEnum.BIG_DATA_OPERATION_DIRECT_LOG.getDesc()));
        operationLogRecordDOs.add(OperationLogRecordUtil.getBigDataOperationLog(opSign, OperationDataEnum.DIRECTLY_SHOP.getTableType(), time + "ms", OpContentEnum.BIG_DATA_OPERATION_DIRECT_LOG.getIndex().toString(),OpContentEnum.BIG_DATA_OPERATION_DIRECT_LOG.getDesc()));
        operationLogRecordDOs.add(OperationLogRecordUtil.getBigDataOperationLog(opSign, OperationDataEnum.PLAN_DEMAND.getTableType(), time + "ms", OpContentEnum.BIG_DATA_OPERATION_DIRECT_LOG.getIndex().toString(),OpContentEnum.BIG_DATA_OPERATION_DIRECT_LOG.getDesc()));
        if (validWeekJob) {
            operationLogRecordDOs.add(OperationLogRecordUtil.getBigDataOperationLog(opSign, OperationDataEnum.DIRECTLY_ACCURACY.getTableType(), time + "ms", OpContentEnum.BIG_DATA_OPERATION_DIRECT_LOG.getIndex().toString(),OpContentEnum.BIG_DATA_OPERATION_DIRECT_LOG.getDesc()));
            operationLogRecordDOs.add(OperationLogRecordUtil.getBigDataOperationLog(opSign, OperationDataEnum.DIRECTLY_DIFFERIN.getTableType(), time + "ms", OpContentEnum.BIG_DATA_OPERATION_DIRECT_LOG.getIndex().toString(),OpContentEnum.BIG_DATA_OPERATION_DIRECT_LOG.getDesc()));
            operationLogRecordDOs.add(OperationLogRecordUtil.getBigDataOperationLog(opSign, OperationDataEnum.PLAN_DIRECTLY.getTableType(), time + "ms", OpContentEnum.BIG_DATA_OPERATION_DIRECT_LOG.getIndex().toString(),OpContentEnum.BIG_DATA_OPERATION_DIRECT_LOG.getDesc()));
        }
        operationLogRecordRepository.batchAddOperationLogRecord(operationLogRecordDOs);
    }

}
